package cc.vv.btpartyjob.partymanager.adapter

import android.annotation.SuppressLint
import android.os.Build
import android.support.annotation.RequiresApi
import android.text.TextUtils
import android.widget.TextView
import cc.vv.BaseNewApplication
import cc.vv.baselibrary.adapter.SimpleCommonAdapter
import cc.vv.baselibrary.adapter.holder.ExtendViewHolder
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.moudel.bean.ProjectQueryObj

/**
 * 项目查询adapter
 * Created by Chen.qi on 2018/10/24.
 */
class ProjectQueryAdapter(layoutResId: Int) : SimpleCommonAdapter<ProjectQueryObj>(layoutResId) {

    @SuppressLint("SetTextI18n")
    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun convert(helper: ExtendViewHolder, item: ProjectQueryObj, position: Int) {
        val viewStatus = helper.getView<TextView>(R.id.tv_ipq_status)
        when (item.sysState) {
            0 -> {
                //正常
                val drawable = BaseNewApplication.getApplication().resources.getDrawable(R.drawable.shape_project_normal_bg)
                viewStatus?.background = drawable
                viewStatus?.text = "正常"
            }
            1 -> {
                //预警
                val drawable = BaseNewApplication.getApplication().resources.getDrawable(R.drawable.shape_project_waring_bg)
                viewStatus?.background = drawable
                viewStatus?.text = "延期"

            }
            2 -> {
                //延期
                val drawable = BaseNewApplication.getApplication().resources.getDrawable(R.drawable.shape_project_postpone_bg)
                viewStatus?.background = drawable
                viewStatus?.text = "预警"

            }
            3 -> {
                //取消
                val drawable = BaseNewApplication.getApplication().resources.getDrawable(R.drawable.shape_project_cancel_bg)
                viewStatus?.background = drawable
                viewStatus?.text = "取消"

            }
            4 -> {
                //结项
                val drawable = BaseNewApplication.getApplication().resources.getDrawable(R.drawable.shape_project_pdsp_bg)
                viewStatus?.background = drawable
                viewStatus?.text = "结项"

            }
        }
        //项目名称
        val tvProjectName = helper.getView<TextView>(R.id.tv_ipq_projectName)
        tvProjectName?.text = item.projectName


        //负责人
        val principalName = helper.getView<TextView>(R.id.tv_ipq_fuZeName)
        principalName?.text = item.principal

        //申报时间
        val tvDeclareTime = helper.getView<TextView>(R.id.tv_ipq_declareTime)
        if (!TextUtils.isEmpty(item.declarationTime) && item.declarationTime!!.length > 10) {
            val substring = item.declarationTime!!.substring(0, 10)
            tvDeclareTime?.text = "申报时间：$substring"
        } else {
            tvDeclareTime?.text = "申报时间：${item.declarationTime}"
        }

        //预警时间
        val tvYuJinTime = helper.getView<TextView>(R.id.tv_ipq_waringTime)
        if (!TextUtils.isEmpty(item.warningTime) && item.warningTime!!.length > 10) {
            val substring = item.warningTime!!.substring(0, 10)
            tvYuJinTime?.text = "预警时间：$substring"
        } else {
            tvYuJinTime?.text = "申报时间：${item.warningTime}"
        }

//        <TextView
//        android:id="@+id/tv_ipq_declareTime"
//        android:layout_width="wrap_content"
//        android:layout_height="wrap_content"
//        android:text="申报时间：2018-10-22"
//        android:textColor="@color/color_BCC3D0"
//        android:textSize="@dimen/sp_12" />
////        projectIntroduction
//        val princalName = helper.getView<TextView>(R.id.tv_ipq_fuZeName)
//        princalName?.text=item.principal
    }
}